#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <Dynamics/Fem/fem_cuda.h>
#include <string>
using namespace PhysLeo;
namespace py = pybind11;

template<typename T>
static void declareFemCpu(py::module &mod, const std::string &typestr)
{
    using class_type = FemCpu<T>;
    using base_type = ForceModule<T>;
    auto pyclass_name = std::string("FemCpu") + typestr;
    py::class_<class_type, base_type, std::shared_ptr<class_type>>cls(mod, pyclass_name.c_str());

    cls.def(py::init());
    cls.def("allocateResource", &class_type::allocateResource);
    cls.def("deformEnergy", &class_type::deformEnergy);
    cls.def("internalForce", &class_type::internalForce);
}

template<typename T>
static void declareFemCuda(py::module &mod, const std::string &typestr)
{
    using class_type = FemCuda<T>;
    using base_type = FemCpu<T>;
    auto pyclass_name = std::string("FemCuda") + typestr;
    py::class_<class_type, base_type, std::shared_ptr<class_type>>cls(mod, pyclass_name.c_str());

    cls.def(py::init());
    cls.def("deformEnergy", &class_type::deformEnergy);
    cls.def("internalForce", &class_type::internalForce);
}

void initFem(py::module &m)
{
    declareFemCpu<float>(m, std::string("F"));
    declareFemCpu<double>(m, std::string("D"));
    
    declareFemCuda<float>(m, std::string("F"));
    declareFemCuda<double>(m, std::string("D"));
}
